package org.trinity.netdisk.controller;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.trinity.netdisk.enums.ResultCode;
import org.trinity.netdisk.exception.file.FileNotExistException;
import org.trinity.netdisk.exception.file.NoNameException;
import org.trinity.netdisk.exception.file.NotEnoughSpaceException;
import org.trinity.netdisk.exception.file.OperationFailedException;
import org.trinity.netdisk.exception.shareFile.InvalidCheckCodeException;
import org.trinity.netdisk.exception.shareFile.InvalidShareDayException;
import org.trinity.netdisk.exception.shareFile.ShareFileExpireException;
import org.trinity.netdisk.exception.user.InvalidParamterException;
import org.trinity.netdisk.exception.user.InvalidVerificationCodeException;
import org.trinity.netdisk.exception.user.NoTokenException;
import org.trinity.netdisk.util.ResponseWrapper;

import java.io.FileNotFoundException;

@RestControllerAdvice
public class ControllerAdvicer {

    @ExceptionHandler(NotEnoughSpaceException.class)
    private Object notEnoughSpaceExceptionHandler() {
        return new ResponseWrapper(ResultCode.NO_ENOUGH_SPACE);
    }

    @ExceptionHandler(NoNameException.class)
    private Object noNameExceptionHandler() {
        return new ResponseWrapper(ResultCode.NO_FILE_NAME);
    }

    @ExceptionHandler(InvalidVerificationCodeException.class)
    private Object invalidVerificationCodeExceptionHander() {
        return new ResponseWrapper(ResultCode.INVALID_VERIFICATION_CODE);
    }

    @ExceptionHandler(OperationFailedException.class)
    private Object operationFailedExceptionHandler() {
        return new ResponseWrapper(ResultCode.OPERATION_FAILED);
    }

    @ExceptionHandler(InvalidCheckCodeException.class)
    private Object invalidCheckCodeExceptionHandler() {
        return new ResponseWrapper(ResultCode.SHARE_FILE_CHECK_CODE_ERROR);
    }

    @ExceptionHandler(ShareFileExpireException.class)
    private Object shareFileExceptonHandler() {
        return new ResponseWrapper(ResultCode.SHARE_LINK_EXPIRED);
    }

    @ExceptionHandler(FileNotFoundException.class)
    private Object fileNotFoundExceptionHandler() {
        return new ResponseWrapper(ResultCode.DATA_NOT_FOUND);
    }

    @ExceptionHandler(NoTokenException.class)
    private Object noTokenExceptionHandler() {
        return new ResponseWrapper(ResultCode.NO_PERMISSION);
    }

    @ExceptionHandler(InvalidShareDayException.class)
    private Object invalidShareDayExceptionHandler(){
        return new ResponseWrapper(ResultCode.INVALID_SHARE_DAYS);
    }

    @ExceptionHandler(InvalidParamterException.class)
    private Object invalidParamterExceptionHandler(){
        return new ResponseWrapper(ResultCode.PARAM_IS_INVALID);
    }

    @ExceptionHandler(FileNotExistException.class)
    private Object FileNotExistExceptionHandler(){
        return new ResponseWrapper(ResultCode.FILE_NOT_FOUND);
    }
}
